<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是蓝牙开发——蓝牙BLE基础知识的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV03-01-蓝牙-02-蓝牙BLE基础">
<meta property="og:url" content="https://sumumm.github.io/post/85707029.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是蓝牙开发——蓝牙BLE基础知识的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223090311655.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223090927839.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223091118890.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223092238613.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223092701293.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223092934681.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223152909366.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223152920083.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223153119764.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223153615302.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223153836841.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223154756215.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223094728191.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/1.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104239625.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104515455.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104621826.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104956898.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223110052622.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223110610059.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104621826.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223111902089.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223112056300.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223112616367.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223112844436.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223113040315.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223113103341.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223113454367.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114003807.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114026698.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114131563.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223115023394.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114320752.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114909792.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223115058268.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223134706721.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223135026045.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223135256582.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223135026045.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223140327324.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142210363.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142251741.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142330264.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142414270.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142810641.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142914342.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142949736.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223143021957.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223143343840.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223144305774.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223144614997.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223144907030.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223150722845.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223150423470.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223163116264.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165727812.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223164226974.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223164827374.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223164612470.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223164956287.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165131874.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165219131.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165319778.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165453992.png">
<meta property="article:published_time" content="2024-01-07T03:45:24.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.026Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV21-天猫精灵IOT">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223090311655.png">


<link rel="canonical" href="https://sumumm.github.io/post/85707029.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/85707029.html","path":"post/85707029.html","title":"LV03-01-蓝牙-02-蓝牙BLE基础"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV03-01-蓝牙-02-蓝牙BLE基础 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%88%9D%E8%AF%86%E8%93%9D%E7%89%99BLE"><span class="nav-text">一、初识蓝牙BLE</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%93%9D%E7%89%99%E6%A6%82%E8%BF%B0"><span class="nav-text">1. 蓝牙概述</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E8%93%9D%E7%89%99%E7%9A%84%E5%8F%91%E5%B1%95%E5%8E%86%E5%8F%B2"><span class="nav-text">1.1 蓝牙的发展历史</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E8%93%9D%E7%89%99%E7%9A%84%E6%8A%80%E6%9C%AF%E4%BC%98%E5%8A%BF"><span class="nav-text">1.2 蓝牙的技术优势</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-%E8%93%9D%E7%89%99BLE%E7%9A%84%E7%BD%91%E7%BB%9C%E7%BB%93%E6%9E%84"><span class="nav-text">1.3 蓝牙BLE的网络结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-4-%E8%93%9D%E7%89%99%E7%9A%84%E4%BF%A1%E9%81%93%E4%B8%8E%E5%B7%A5%E4%BD%9C%E9%A2%91%E6%AE%B5"><span class="nav-text">1.4 蓝牙的信道与工作频段</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%93%9D%E7%89%99BLE%E5%8D%8F%E8%AE%AE%E7%AE%80%E4%BB%8B"><span class="nav-text">2. 蓝牙BLE协议简介</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E8%93%9D%E7%89%99%E7%BB%93%E6%9E%84%E6%A6%82%E8%BF%B0"><span class="nav-text">2.1 蓝牙结构概述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-BT%E4%B8%8EBLE"><span class="nav-text">2.2 BT与BLE</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-1-Controller"><span class="nav-text">2.2.1 Controller</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-Host"><span class="nav-text">2.2.2 Host</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E4%B8%BA%E4%BB%80%E4%B9%88%E8%BF%99%E4%B9%88%E5%A4%9A%E5%8D%8F%E8%AE%AE"><span class="nav-text">2.3 为什么这么多协议</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E8%93%9D%E7%89%99%E8%A7%84%E8%8C%83"><span class="nav-text">2.4 蓝牙规范</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-%E5%8D%8F%E8%AE%AE%E6%A1%86%E6%9E%B6"><span class="nav-text">2.5 协议框架</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%A6%82%E4%BD%95%E5%8F%91%E9%80%81%E4%B8%80%E4%B8%AA%E6%97%A0%E7%BA%BF%E6%95%B0%E6%8D%AE%E5%8C%85"><span class="nav-text">3. 如何发送一个无线数据包  </span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E8%93%9D%E7%89%99BLE%E7%89%A9%E7%90%86%E5%B1%82-PHY"><span class="nav-text">二、蓝牙BLE物理层(PHY)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%89%A9%E7%90%86%E5%B1%82%E8%A6%81%E5%81%9A%E4%BB%80%E4%B9%88%EF%BC%9F"><span class="nav-text">1. 物理层要做什么？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BF%A1%E5%8F%B7%E8%B0%83%E5%88%B6"><span class="nav-text">2. 信号调制</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E6%A8%A1%E6%8B%9F%E8%B0%83%E5%88%B6"><span class="nav-text">2.1 模拟调制</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E6%95%B0%E5%AD%97%E8%B0%83%E5%88%B6"><span class="nav-text">2.2 数字调制</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%B0%84%E9%A2%91%E9%A2%91%E6%AE%B5"><span class="nav-text">3. 射频频段</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%B0%84%E9%A2%91%E4%BF%A1%E9%81%93"><span class="nav-text">4. 射频信道</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E7%89%A9%E7%90%86%E5%B1%82%E5%A6%82%E4%BD%95%E8%AF%86%E5%88%AB0%E5%92%8C1%EF%BC%9F"><span class="nav-text">5. 物理层如何识别0和1？</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E8%93%9D%E7%89%99BLE%E9%93%BE%E8%B7%AF%E5%B1%82-Link"><span class="nav-text">三、蓝牙BLE链路层(Link)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%99%BD%E5%8C%96"><span class="nav-text">1. 白化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E9%93%BE%E8%B7%AF%E5%B1%82%E7%8A%B6%E6%80%81%E6%9C%BA"><span class="nav-text">2. 链路层状态机</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%B0%B1%E7%BB%AA%E6%80%81"><span class="nav-text">2.1 就绪态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E6%89%AB%E6%8F%8F%E6%80%81"><span class="nav-text">2.2 扫描态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E5%8F%91%E8%B5%B7%E6%80%81"><span class="nav-text">2.3 发起态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E8%BF%9E%E6%8E%A5%E6%80%81"><span class="nav-text">2.4 连接态</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-%E5%B9%BF%E6%92%AD%E6%80%81"><span class="nav-text">2.5 广播态</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%95%B0%E6%8D%AE%E5%8C%85%E6%A0%BC%E5%BC%8F"><span class="nav-text">3. 数据包格式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E5%89%8D%E5%AF%BC%E6%A0%BC%E5%BC%8F"><span class="nav-text">3.1 前导格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E6%8E%A5%E5%85%A5%E5%9C%B0%E5%9D%80"><span class="nav-text">3.2 接入地址</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E6%8A%A5%E5%A4%B4"><span class="nav-text">3.3 报头</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-1-%E5%B9%BF%E6%92%AD%E6%8A%A5%E5%A4%B4"><span class="nav-text">3.3.1 广播报头</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-3-2-%E6%95%B0%E6%8D%AE%E6%8A%A5%E5%A4%B4"><span class="nav-text">3.3.2 数据报头</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-%E9%95%BF%E5%BA%A6"><span class="nav-text">3.4 长度</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E4%BF%A1%E9%81%93%E6%98%A0%E5%B0%84"><span class="nav-text">4. 信道映射</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E8%B7%B3%E9%A2%91"><span class="nav-text">5. 跳频</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E6%8E%A7%E5%88%B6%E6%8E%A5%E5%8F%A3%E5%B1%82-HCI"><span class="nav-text">四、控制接口层(HCI)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%A4%E7%A7%8D%E6%8E%A5%E5%8F%A3%E7%9A%84%E6%A6%82%E5%BF%B5"><span class="nav-text">1. 两种接口的概念</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F"><span class="nav-text">2. 数据格式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%91%BD%E4%BB%A4%E6%95%B0%E6%8D%AE%E5%8C%85%E6%A0%BC%E5%BC%8F"><span class="nav-text">2.1 命令数据包格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E4%BA%8B%E4%BB%B6%E6%95%B0%E6%8D%AE%E5%8C%85%E6%A0%BC%E5%BC%8F"><span class="nav-text">2.2 事件数据包格式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%8A%9F%E8%83%BD%E8%AF%B4%E6%98%8E"><span class="nav-text">3. 功能说明</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E5%A4%8D%E4%BD%8D"><span class="nav-text">3.1 复位</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E8%AF%BB%E5%8F%96MAC%E5%9C%B0%E5%9D%80"><span class="nav-text">3.2 读取MAC地址</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E8%AE%BE%E7%BD%AE%E4%BA%8B%E4%BB%B6%E6%8E%A9%E7%A0%81"><span class="nav-text">3.3 设置事件掩码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-%E8%AF%BB%E5%8F%96%E7%BC%93%E5%86%B2%E5%8C%BA%E5%A4%A7%E5%B0%8F"><span class="nav-text">3.4 读取缓冲区大小</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-5-%E8%AF%BB%E5%8F%96%E6%8E%A7%E5%88%B6%E5%99%A8%E6%94%AF%E6%8C%81%E7%9A%84%E5%8A%9F%E8%83%BD"><span class="nav-text">3.5 读取控制器支持的功能</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94%E3%80%81%E9%80%BB%E8%BE%91%E9%93%BE%E8%B7%AF%E6%8E%A7%E5%88%B6%E5%92%8C%E9%80%82%E9%85%8D%E5%8D%8F%E8%AE%AE%E5%B1%82-L2CAP"><span class="nav-text">五、逻辑链路控制和适配协议层(L2CAP)</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%AD%E3%80%81%E5%B1%9E%E6%80%A7%E5%8D%8F%E8%AE%AE%E5%92%8C%E9%80%9A%E7%94%A8%E5%B1%9E%E6%80%A7%E5%8D%8F%E8%AE%AE"><span class="nav-text">六、属性协议和通用属性协议</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-ATT%E5%B1%9E%E6%80%A7%E5%8D%8F%E8%AE%AE"><span class="nav-text">1. ATT属性协议</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%B8%8E%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="nav-text">1.1 客户端与服务器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E5%B1%9E%E6%80%A7%E7%9A%84%E6%A0%BC%E5%BC%8F"><span class="nav-text">1.2 属性的格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-%E5%B1%9E%E6%80%A7%E5%AE%9E%E4%BE%8B"><span class="nav-text">1.3 属性实例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-GATT%E9%80%9A%E7%94%A8%E5%B1%9E%E6%80%A7%E5%8D%8F%E8%AE%AE"><span class="nav-text">2. GATT通用属性协议</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-GATT%E6%9C%8D%E5%8A%A1"><span class="nav-text">2.1 GATT服务</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-GATT%E7%89%B9%E5%BE%81"><span class="nav-text">2.2 GATT特征</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-GATT%E6%8F%8F%E8%BF%B0%E7%AC%A6"><span class="nav-text">2.3 GATT描述符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-GATT%E5%A3%B0%E6%98%8E"><span class="nav-text">2.4 GATT声明</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/85707029.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV03-01-蓝牙-02-蓝牙BLE基础 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV03-01-蓝牙-02-蓝牙BLE基础
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-01-07 11:45:24" itemprop="dateCreated datePublished" datetime="2024-01-07T11:45:24+08:00">2024-01-07</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/" itemprop="url" rel="index"><span itemprop="name">LV21-天猫精灵IOT</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>15k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>53 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是蓝牙开发——蓝牙BLE基础知识的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows版本</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu版本</td>        <td align="left">Ubuntu22.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="6">官方网站</td>        <td align="left"><a href="https://cn.aliyun.com/" target="_blank">阿里云</a></td>        <td align="left">阿里云官网主页</td>    </tr>    <tr>        <td align="left"><a href="https://www.aliyun.com/product/iot/livinglink?spm=5176.28508143.J_4VYgf18xNlTAyFFbOuOQe.317.5421154acZniIL&scm=20140722.X_data-1da961ea118f5bb0e4b2._.V_1" target="_blank">阿里生活物联平台</a></td>        <td align="left">生活物联网平台(飞燕平台)主页</td>    </tr>    <tr>        <td align="left"><a href="https://iap.aligenie.com/?spm=0.7629140.0.0.2c611780Ty6tzg" target="_blank">AliGenie</a></td>        <td align="left">天猫精灵开放平台AliGenie主页</td>    </tr>    <tr>        <td align="left"><a href="https://www.aliyun.com/product/iot/iot_instc_public_cn?spm=5176.28508143.J_4VYgf18xNlTAyFFbOuOQe.81.5421154au3ocqp&scm=20140722.X_data-9349178ba84cf028806a._.V_1" target="_blank">阿里物联网平台</a></td>        <td align="left">阿里物联网平台主页</td>    </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/" target="_blank">Bluetooth 技术网站</a></td>        <td align="left">蓝牙协议规范什么的可以来这里找</td>    </tr>    <tr>        <td align="left"><a href="https://www.telink-semi.com/" target="_blank">Telink</a></td>        <td align="left">Telink | Chips for a Smarter IoT (telink-semi.com)<br><a href="https://www.telink-semi.cn/" target="_blank">Telink中文官网</a></td>    </tr>    <tr>        <td align="center" rowspan="5">开发手册</td>        <td align="left"><a href="https://help.aliyun.com/zh/alios-things/" target="_blank">AliOS Things开发指南</a></td>        <td align="left">AliOS Things开发指南，这里是最新版本，可以直接从官网找到</td>    </tr>     <tr>        <td align="left"><a href="https://haas.iot.aliyun.com/aliosthings/index.html" target="_blank">AliOS Things开发指南</a></td>        <td align="left">AliOS Things应用开发指南，这里应该是3.3版本的完整开发文档</td>    </tr>    <tr>        <td align="left"><a href="https://gaic.alicdn.com/aic/h5_daily/test/aliosthings/3.0.13/index.html" target="_blank">AliOS Things开发指南(3.0)</a></td>        <td align="left">AliOS Things应用开发指南，这里应该是3.0版本的完整开发文档</td>    </tr>    <tr>        <td align="left"><a href="https://help.aliyun.com/product/123207.html?spm=a2c4g.11186623.6.540.114e60d84sF58G" target="_blank">生活物联网平台开发文档</a></td>        <td align="left">生活物联网平台（飞燕平台）开发文档<br><a href="https://help.aliyun.com/document_detail/180778.html?spm=a2c4g.123207.0.0.49556adcO5apvd" target="_blank">《设备端开发指南》</a></td>    </tr>    <tr>        <td align="left"><a href="https://doc-bot.tmall.com/docs/doc.htm?spm=0.7629140.0.0.7bf81780UN7WkQ&treeId=578&articleId=118057&docType=1" target="_blank">Wi-Fi IoT品类定义与功能开发</a></td>        <td align="left">天猫精灵IoT开放平台——Wi-Fi IoT品类定义与功能开发</td>    </tr>    <tr>        <td align="center" rowspan="3">硬件平台</td>        <td align="left"><a href="https://developer.aliyun.com/article/761644?spm=a2c6h.12873581.0.dArticle761644.1c1b589dRHgvcR&groupCode=genieaiot" target="_blank">mk3080 WiFi开发板</a></td>        <td align="left">WiFi开发板使用指南-阿里云开发者社区</td>    </tr>    <tr>        <td align="left"><a href="http://www.taichi-maker.com/homepage/esp8266-nodemcu-iot/esp8266-nodemcu-tutorial-index/" target="_blank">esp8266开发板</a></td>        <td align="left">一个教程：ESP8266-NodeMCU开发板详解-太极创客 (taichi-maker.com)</td>    </tr>    <tr>        <td align="left"><a href="https://wiki.telink-semi.cn/doc/ds/DS_TLSR8258-E_Datasheet%20for%20Telink%20BLE+IEEE802.15.4%20Multi-Standard%20Wireless%20SoC%20TLSR8258.pdf" target="_blank">TLSR8258 Datasheet</a></td>        <td align="left">Datasheet for Telink BLE + IEEE802.15.4 MultiStandard Wireless SoC TLSR8258</td>    </tr>    <tr>        <td align="center" rowspan="2">参考资料</td>        <td align="left"><a href="https://developer.aliyun.com/article/720516#" target="_blank">AliOS Things 3.0 应用开发指南</a></td>        <td align="left">这个只是一篇参考文章，里面是一些环境搭建相关的，可以参考</td>    </tr>    <tr>        <td align="left"><a href="https://info.support.huawei.com/info-finder/encyclopedia/zh/index.html" target="_blank">IP知识百科 - 华为 (huawei.com)</a></td>        <td align="left">IP的一些相关知识点</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="left" rowspan="6">蓝牙规范相关文档</td>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/specifications/specs/core-specification-5-2/" target="_blank">Core Specification 5.2</a></td>        <td align="left">核心规格 5.2，该规范定义了创建可互操作的Bluetooth 设备所需的技术。                        <br><a href="./蓝牙参考资料/Core_v5.2.pdf" target="_blank">《Core_v5.2.pdf》</a></td>      </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/specifications/specs/mesh-model-1-1/" target="_blank">Mesh Model(v1.1)</a></td>        <td align="left">本Bluetooth 规范定义了模型（以及它们所需的状态和消息），这些模型用于在mesh 网络中的节点上执行基本功能，超出了Bluetooth Mesh 配置文件 规范中定义的基础模型。                        <br>本规范包括定义跨设备类型标准功能的通用模型，以及支持关键mesh 场景的模型，如照明控制、传感器、时间和场景。                        <br><a href="./蓝牙参考资料/MshMDL_v1.1.pdf" target="_blank">《MshMDL_v1.1.pdf》</a></td>      </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/specifications/specs/mesh-profile-1-0-1/" target="_blank">Mesh Profile(v1.0.1)</a></td>        <td align="left">该Bluetooth 规范定义了基本要求，以实现可互操作的mesh 网络解决方案，用于Bluetooth 低能量无线技术。                        <br><a href="./蓝牙参考资料/MshPRFv1.0.1.pdf" target="_blank">《MshPRFv1.0.1.pdf》</a></td>      </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/zh-cn/specifications/device-properties/" target="_blank">Mesh Device Properties</a></td>        <td align="left">本规范包含Bluetooth Mesh 配置文件 和Bluetooth Mesh 模型规范所要求的设备属性的定义。                        <br>但是跟之前的有些区别，我主要看的之前的版本：<a href="./蓝牙参考资料/MeshDeviceProperties_v1.2.pdf" target="_blank">《MMeshDeviceProperties_v1.2.pdf》</a></td>      </tr>    <tr>        <td align="left"><a href="https://www.bluetooth.com/specifications/gss/" target="_blank">GATT Specification Supplement</a></td>        <td align="left">GATT Specification Supplement | Bluetooth® Technology Website。                        <br>好像可以在线看：<a href="https://btprodspecificationrefs.blob.core.windows.net/gatt-specification-supplement/GATT_Specification_Supplement.pdf" target="_blank">《GATT Specification Supplement》</a></td>      </tr>     <tr>        <td align="left"><a href="https://www.bluetooth.com/specifications/assigned-numbers/" target="_blank">Assigned Numbers</a></td>        <td align="left">GATT的一些类型定义可以在这里找。</td>      </tr>    <tr>        <td align="left" rowspan="2">AliOS Things</td>        <td align="left"><a href="https://gitee.com/alios-things-admin/AliOS-Things" target="_blank">alios-things/AliOS-Things</a></td>        <td align="left">Gitee上的AliOSThings SDK源码仓库</td>      </tr>    <tr>        <td align="left"><a href="https://github.com/alibaba/AliOS-Things" target="_blank">alibaba/AliOS-Things</a></td>        <td align="left">GitHub上的AliOSThings SDK源码仓库</td>      </tr>    <tr>        <td align="left" rowspan="2">天猫精灵蓝牙Mesh协议栈</td>        <td align="left"><a href="https://github.com/alibaba-archive/genie-bt-mesh-stack" target="_blank">alibaba-archive/genie-bt-mesh-stack</a></td>        <td align="left">GitHub上的天猫精灵蓝牙Mesh协议栈源码仓库。<br>之前是在<a href="https://github.com/alibaba/genie-bt-mesh-stack"target="_blank">alibaba/genie-bt-mesh-stack</a>这个仓库。<br>写笔记的时候最新提交为<a href="https://github.com/alibaba-archive/genie-bt-mesh-stack/tree/faf523618a6a2560090fc423222b9db80984bb7a" target="_blank">faf523618a6a2560090fc423222b9db80984bb7a</a></td>      </tr>    <tr>        <td align="left"><a href="https://help.aliyun.com/document_detail/171552.html?spm=a2c4g.173310.0.0.55d6e992e8xJip" target="_blank">蓝牙Mesh设备开发指南</a></td>        <td align="left">阿里云生活服务平台开发手册——蓝牙设备开发一节中的内容</td>      </tr></table>
              </div>
            </details>


<h1 id="一、初识蓝牙BLE"><a href="#一、初识蓝牙BLE" class="headerlink" title="一、初识蓝牙BLE"></a><font size=3>一、初识蓝牙BLE</font></h1><h2 id="1-蓝牙概述"><a href="#1-蓝牙概述" class="headerlink" title="1. 蓝牙概述"></a><font size=3>1. 蓝牙概述</font></h2><h3 id="1-1-蓝牙的发展历史"><a href="#1-1-蓝牙的发展历史" class="headerlink" title="1.1 蓝牙的发展历史"></a><font size=3>1.1 蓝牙的发展历史</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223090311655.png" alt="image-20231223090311655" style="zoom:50%;" />

<p>经典蓝牙（BT）和低功耗蓝牙（BLE）。蓝牙4.0之后才对低功耗支持，4.0之前都属于经典蓝牙，虽然都是蓝牙技术，但其两种方案的差别还是非常大的。  </p>
<h3 id="1-2-蓝牙的技术优势"><a href="#1-2-蓝牙的技术优势" class="headerlink" title="1.2 蓝牙的技术优势"></a><font size=3>1.2 蓝牙的技术优势</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223090927839.png" alt="image-20231223090927839" style="zoom:50%;" />

<p>WiFi需要连接电源，功耗高。zigbee在一些恶劣的环境下也能很好的工作，但是它的传输速率限制在250KB&#x2F;S，不适用于大量数据的传输。蓝牙传输速率会高很多，并且抗干扰能力也更强，连接速度也更快：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223091118890.png" alt="image-20231223091118890" style="zoom:50%;" />

<h3 id="1-3-蓝牙BLE的网络结构"><a href="#1-3-蓝牙BLE的网络结构" class="headerlink" title="1.3 蓝牙BLE的网络结构"></a><font size=3>1.3 蓝牙BLE的网络结构</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223092238613.png" alt="image-20231223092238613" style="zoom:50%;" />

<p>蓝牙BLE是一个星型网络，一个主机可以有多个从机，数据可以通过广播的方式发送给主机。蓝牙BLE协议栈的基本层级如下，后面还会做详细的学习。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223092701293.png" alt="image-20231223092701293" style="zoom:50%;" />

<h3 id="1-4-蓝牙的信道与工作频段"><a href="#1-4-蓝牙的信道与工作频段" class="headerlink" title="1.4 蓝牙的信道与工作频段"></a><font size=3>1.4 蓝牙的信道与工作频段</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223092934681.png" alt="image-20231223092934681" style="zoom:50%;" />

<p>37、38和39是蓝牙BLE的广播信道，这些信道与WiFi的信道是不重叠的，不受WiFi影响。蓝牙的工作频段为2400Mhz ~ 2483.5Mhz，一共被分为80个信道，每个信道的相差1Mhz，蓝牙连接管理使用连接管理协议(Link Manager Protocol LMP)，而在低功耗蓝牙里则信道被分为40Mhz，每个信道相差2Mz，蓝牙连接管理使用连接层（Link Layer)，空中数据包的结构也完全不同。  </p>
<h2 id="2-蓝牙BLE协议简介"><a href="#2-蓝牙BLE协议简介" class="headerlink" title="2. 蓝牙BLE协议简介"></a><font size=3>2. 蓝牙BLE协议简介</font></h2><h3 id="2-1-蓝牙结构概述"><a href="#2-1-蓝牙结构概述" class="headerlink" title="2.1 蓝牙结构概述"></a><font size=3>2.1 蓝牙结构概述</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png" alt="image-20231223085657235" style="zoom:50%;" />

<p>通过上面的图片可以很明显的看出来，蓝牙是分为Host和Controller两个部分的，他们之间的数据结交互有串口、USB、SDIO等等使用HCI协议进行连接和通信、这么做的好处是便于升级。举个例子用户买了一台不带蓝牙的笔记本，后期只需要购买一个USB蓝牙控制器即可实现对蓝牙的支持，这里面电脑本身相当于Host，USB蓝牙控制器则是Controller，虽然现在不少芯片把Host和Controller放到了一颗芯片上，但基本还是遵循这样的层次结构，只是将HCI协议从硬件通信端口变成了软件端口。</p>
<p>Host的功能主要是对各种应用场景的支持，从上图中可以看到熟悉的A2DP(Advanced Audio Distribution Profile)用于蓝牙耳机接收音频场景，AVRCP(A&#x2F;V Remote Control Profile)用于音乐播放控制场景等，作为低功耗的代表，无线鼠标键盘，则是使用了HGOP(HID Over GATT Profile)场景，才能让蓝牙鼠标键盘实现充一次电用一个星期的目的，当然上图中所支持的场景并不是全部，其实还包括像(Basic Printing Profile），心率（Heart Rate Profile)等规范来适应不同的场景。Controller的功能部分多数是由蓝牙芯片厂商来负责的，主要在射频等内容。  </p>
<h3 id="2-2-BT与BLE"><a href="#2-2-BT与BLE" class="headerlink" title="2.2 BT与BLE"></a><font size=3>2.2 BT与BLE</font></h3><p>前面我们知道BT是经典蓝牙，BLE是低功耗蓝牙。</p>
<h4 id="2-2-1-Controller"><a href="#2-2-1-Controller" class="headerlink" title="2.2.1 Controller"></a><font size=3>2.2.1 Controller</font></h4><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223152909366.png" alt="image-20231223152909366" style="zoom:50%;" />

<p>Controler部分是完全是两个独立的通道，经典蓝牙和低功耗蓝牙的Controller可以独立存在，互相不依赖，所以目前市面上有只支持经典蓝牙的芯片，也有只支持低功耗蓝牙芯片，当然，也有两种蓝牙模式共存的芯片。  </p>
<h4 id="2-2-2-Host"><a href="#2-2-2-Host" class="headerlink" title="2.2.2 Host"></a><font size=3>2.2.2 Host</font></h4><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223152920083.png" alt="image-20231223152920083" style="zoom:40%;" />

<p>在Host端，经典蓝牙和低功耗蓝牙的设计思路也不一样，在经典蓝牙协议里，在逻辑链路控制与适配协议层(Logical Link Control and Adaptation Protocol L2CAP)之上，还根据不同的应用场景定义了不同的传输协议，例如RFCOM， AVDTP，AVCTP，在不同的传输协议之上才定义了不同的Profile，层次结构比较复杂，开发人员学习成本高。而低功耗蓝牙就比较简单，只定义了一个属性协议(AttributeProtocol ATT)，基于属性协议定义了一个通用属性场景规范(Generic Attribute Profile GATT)和其他的针对特定业务的场景规范(Profile)，开发起来比较简单，整体框架也比较容易实现私有场景的开发。  </p>
<h3 id="2-3-为什么这么多协议"><a href="#2-3-为什么这么多协议" class="headerlink" title="2.3 为什么这么多协议"></a><font size=3>2.3 为什么这么多协议</font></h3><p>蓝牙这么多协议分别都是做什么的？其实蓝牙规范也是遵循TCP&#x2F;IP通信模型设计的，让我们把蓝牙协议和TCP&#x2F;IP网络通信模型对应起来就明白了。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223153119764.png" alt="image-20231223153119764" style="zoom:50%;" />

<p>经典蓝牙和低功耗蓝牙大都是点对点直连通信，完全不需要路由功能，所以没有特地定义网络层的协议，简单的寻址功能就在数据链路层的LMP层和LL层实现了，而蓝牙mesh由于是组建了mesh网络，有数据转发和寻址的需求，所以定义了一个Network Layer来做这件事情。  </p>
<h3 id="2-4-蓝牙规范"><a href="#2-4-蓝牙规范" class="headerlink" title="2.4 蓝牙规范"></a><font size=3>2.4 蓝牙规范</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223153615302.png" alt="image-20231223153615302" style="zoom:50%;" />

<p>（1）核心规范：Core Specifications，定义了蓝牙技术最核心的内容。覆盖了从物理层一直到传输层的内容。</p>
<p>（2）Protocol规范： Protocol Specfications，在核心规范之上针对某一大类场景(例如音视频传输，线缆通信传输，网络通信传输)的数据通信需求来定义的传输协议，属于应用层协议，只在经典蓝牙中存在。</p>
<p>（3）Profile规范：包含经典蓝牙的Traditional Profile Specifications和低功耗蓝牙的GATT Specifications。这类规范是针对某一个特定场景需求(例如听音乐，打电话)来对核心规范和protocol做出更细化的定义和对这些协议无法满足的一些细化需求做了补充协议。</p>
<p>（4）蓝牙mesh规范：Mesh Networking Specifications，这是蓝牙最新的mesh规范。只使用了低功耗蓝牙</p>
<p>（5）还有就是一个需要注意的地方就是预分配序号：Assigned Numbers（主要是ATT和GATT会用到），蓝牙组织对某些字段的已经分配的数据定义，例如公司名，广播报文类型等等，都在这里可以查到。当然，还有一些协议修订案(Specification Errata)和蓝牙兼容性测试的文档，以及正在讨论开发中的文档草案，这些不是专门做蓝牙技术的工作的话可以不用关心。  </p>
<h3 id="2-5-协议框架"><a href="#2-5-协议框架" class="headerlink" title="2.5 协议框架"></a><font size=3>2.5 协议框架</font></h3><p>上面了解了这么多，下面就对协议栈，对每一层的规范进行学习。  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223153836841.png" alt="image-20231223153836841" style="zoom: 67%;" />

<p>一般来说，把某个协议实现的代码被称为协议栈（protocol stack），BLE协议栈其实就是实现低功耗蓝牙协议的一堆代码，理解和掌握BLE协议是掌握BLE协议栈的前提，BLE协议栈主要由以下几部分组成：</p>
<ul>
<li>（1）PHY层(Physical layer 物理层)</li>
</ul>
<p>PHY层用来指定BLE所用的无线频段，调制解调方式和方法等，PHY层的质量直接决定BLE芯片的功耗，灵敏度以及selectivity等射频指标。</p>
<ul>
<li>（2）LL层(Link Layer 链路层)</li>
</ul>
<p>LL层是整个BLE协议栈的核心，也是BLE协议栈的重点，LL层要做的事情非常多，如具体选择哪个射频通道通信，怎么识别空中数据包，具体在什么时间把数据包发出去，怎么保证数据的完整性，ACK如何接收，如何重传，以及如何对链路层管理，控制等等。LL层只负责把数据发出去或者收回来，数据如何解析则是交给上层的GAP或者ATT来完成。  </p>
<ul>
<li>（3）HCI层(Host controller interface 主机控制器接口层)</li>
</ul>
<p>HCI主要用于两颗芯片实现BLE协议栈的场合，用来规范两只之间的通信协议和通信命令等。  </p>
<ul>
<li>（4）GAP层（Generic access profile 通用访问规范）</li>
</ul>
<p>GAP是对LL层payload（有效数据包）进行解析的一种方式，GAP简单的对LL payload进行一些规范和定义，因此GAP能实现的功能非常有限。GAP最主要的功能是广播，扫描和发起连接等。  </p>
<ul>
<li>L2CAP层（Logic link control and adaptation protocol 逻辑链路控制和适配协议）</li>
</ul>
<p>L2CAP对LL进行了一次简单封装，LL只关心传输的数据本身，L2CAP就要区分是加密通道还是普通通道，同时还要对连接间隔进行管理。  </p>
<ul>
<li>SMP（Secure manager protocol 安全管理器）</li>
</ul>
<p>SMP用来管理BLE连接的加密和安全的，如何保证连接的安全性，同时不影响用户的体验，这些都是SMP要考虑的工作。</p>
<ul>
<li>ATT（Attribute protocol 属性协议）</li>
</ul>
<p>ATT层用来定义用户命令及命令操作的数据，比如读取某个数据或者写某个数据。BLE协议栈中，开发者接触最多的就是ATT，BLE引入了attribute（属性）概念，用来描述一条一条的数据。Attribute除了定义数据，同时定义该数据可以使用的ATT命令，因此这一层被称为ATT层。</p>
<ul>
<li>GATT（Generic attribute profile 通用属性规范）</li>
</ul>
<p>GATT用来规范attribute中的数据内容，并运用group（分组）的概念对attribute进行分类管理。没有GATT，BLE协议栈也能跑，但互联互通就会出问题，也正是因为有了GATT和各种各样的应用profile，BLE摆脱了ZigBee等无线协议的兼容性困境，成了出货量最大的2.4G无线通信产品。</p>
<h2 id="3-如何发送一个无线数据包"><a href="#3-如何发送一个无线数据包" class="headerlink" title="3. 如何发送一个无线数据包  "></a><font size=3>3. 如何发送一个无线数据包  </font></h2><p>假设有设备A和设备B，设备A要把自己的电量（0x50）发送给设备B，如果我们使用串口通信，则可以使用uart_send(0x50)的方式进行数据发送，其中的寄存器控制库已经帮我们实现了，而我们在BLE协议栈中开发，也是这个道理，只需要调用对应的函数，如send(0x50)就可以了，剩下的事情协议栈会帮我们处理，虽然我们仅仅填写了0x50，但是空中数据肯定不止这一个信息。</p>
<p>我们既然要通信，肯定要涉及到无线信道，那么假设我们的无线信道为2402M，我们调用了send(0x50)，那么send(0x50)对应的还会调用 send_LL(0x53,2402M)。</p>
<p>设备B是如何知道数据包属于自己呢，为此BLE引入了access address（访问地址）的概念，用来指定接收者的身份，其中0x8E89BED6这个地址比较特殊，它标识发送给周边的所有设备，也就是广播。如果我们要一对一进行通信，设备A的数据包只有设备B来接收，同样B发送的数据包只能A接收，那么就必须生成一个指定的access address用于二者通信。  </p>
<p>先来看一下广播，因为广播较为简单，我们把设备A叫advertiser（广播者），设备B叫scanner或者observer（扫描者）。广播状态下设备A的LL层API将变成send_LL(0x53,2402M, 0x8E89BED6)。由于设备B可以同时接收到很多设备的广播，因此数据包还必须包含设备A的device address（0xE1022AAB753B）以确认该广播包来自设备A，为此send_LL参数需要变成(0x53,2402M, 0x8E89BED6, 0xE1022AAB753B)。LL层还要检查数据的完整性，即数据在传输过程中有没有发生窜改，为此引入CRC24对数据包进行检验 (假设为0xB2C78E) 。同时为了调制解调电路工作更高效，每一个数据包的最前面会加上1个字节的preamble（前导帧），preamble一般为0x55或者0xAA。这样，整个空中包就变成（注：空中包用小端模式表示！）：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223154756215.png" alt="image-20231223154756215" style="zoom: 80%;" />

<p>上面这个数据包还有如下问题：</p>
<p>（1）没有对数据包进行分类组织，设备B无法找到自己想要的数据0x53。为此我们需要在access address之后加入两个字段：LL header和长度字节。LL header用来表示数据包的LL类型，长度字节用来指明payload的长度</p>
<p>（2）设备B什么时候开启射频窗口以接收空中数据包？如上图case1所示，当设备A的数据包在空中传输的时候，设备B把接收窗口关闭，此时通信将失败；同样对case2来说，当设备A没有在空中发送数据包时，设备B把接收窗口打开，此时通信也将失败。只有case3的情况，通信才能成功，即设备A的数据包在空中传输时，设备B正好打开射频接收窗口，此时通信才能成功，换句话说，<strong>LL层还必须定义通信时序</strong>。</p>
<p>（3）当设备B拿到数据0x53后，该如何解析这个数据呢？它到底表示湿度还是电量，还是别的意思？这个就是GAP层要做的工作，GAP层引入了LTV（Length-Type-Value）结构来定义数据，比如020105，02-长度，01-类型（强制字段，表示广播flag，广播包必须包含该字段），05-值。由于广播包最大只能为31个字节，它能定义的数据类型极其有限，像这里说的电量，GAP就没有定义，因此要通过广播方式把电量数据发出去，只能使用供应商自定义数据类型0xFF，即04FF590053，其中04表示长度，FF表示数据类型（自定义数据），0x0059是供应商ID（自定义数据中的强制字段），0x53就是我们的数据(设备双方约定0x53就是表示电量，而不是其他意思)。  </p>
<p>最终空中传输的数据包将变成：  </p>
<figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">AA D6BE898E 60 0E 3B75AB2A02E1 02010504FF590053 8EC7B2</span><br><span class="line"></span><br><span class="line">AA：前导帧(preamble)</span><br><span class="line">D6BE898E：访问地址(access address)</span><br><span class="line">60：LL帧头字段(LL header)</span><br><span class="line">0E：有效数据包长度(payload length)</span><br><span class="line">3B75AB2A02E1：广播者设备地址(advertiser address)</span><br><span class="line">02010504FF590053：广播数据</span><br><span class="line">8EC7B2：CRC24值</span><br></pre></td></tr></table></figure>

<h1 id="二、蓝牙BLE物理层-PHY"><a href="#二、蓝牙BLE物理层-PHY" class="headerlink" title="二、蓝牙BLE物理层(PHY)"></a><font size=3>二、蓝牙BLE物理层(PHY)</font></h1><h2 id="1-物理层要做什么？"><a href="#1-物理层要做什么？" class="headerlink" title="1. 物理层要做什么？"></a><font size=3>1. 物理层要做什么？</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png" alt="image-20231223085657235" style="zoom:50%;" />

<p>物理层主要是接收和发送数据，这一节我们来简单了解一下物理层是如何收发数据，如何分辨数据0和1的。这一部分位于Controller的BLE Base Band这一部分。我们知道进行无线通信的时候，想要收发数据，是离不开射频的。</p>
<p>射频简称RF，是高频交流变化电磁波的简称。电磁波其实就是比较熟悉的概念了。依据麦克斯韦的电磁场理论：振荡的电场产生振荡的磁场，振荡的磁场产生振荡的电场。</p>
<h2 id="2-信号调制"><a href="#2-信号调制" class="headerlink" title="2. 信号调制"></a><font size=3>2. 信号调制</font></h2><h3 id="2-1-模拟调制"><a href="#2-1-模拟调制" class="headerlink" title="2.1 模拟调制"></a><font size=3>2.1 模拟调制</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223094728191.png" alt="image-20231223094728191" style="zoom:50%;" />

<p>一个1元硬币和一个9V电池，这样碰撞就可以产生电磁波，我们使用收音机调节到一个没有台的频道上，就会接收到有干扰的信号，会有一些声音发出。这就是最开始的无线电通信的方式，这样的电磁波没有频段划分，功率很小，传输距离也很近。那为了把消息信号传输到很远很远的地方，我们该怎么办呢？此时就通过高频率和高能量的载波信号来帮助我们实现，它传播距离更远，不容易受外部干扰的影响，这种高能量或高频信号称为载波信号。既然我们可以使用载波信号帮助我们将消息信号传输到很远的距离，那么如何将消息信号和载波信号进行结合呢？我们知道，一个信号包括了幅度、频率和相位，那么我们可以根据消息信号的幅度来改变载波信号的幅度、频率和相位，即<strong>模拟调制可分为三种类型：调幅（AM）、调频（FM）、相位调制（PM）。</strong></p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/1.png" alt="img" style="zoom:50%;" />

<p>在调制过程中，载波信号的特性会根据调制方式发生变化，但是我们要传输的消息信号的特性是不会发生改变。</p>
<ul>
<li>AM调制信号</li>
</ul>
<p><video src="LV03-01-蓝牙-01-蓝牙BLE基础/img/调幅信号.mp4" width=auto height=auto;>调幅信号示例</video></p>
<ul>
<li>FM调频信号</li>
</ul>
<p><video src="LV03-01-蓝牙-01-蓝牙BLE基础/img/调频信号.mp4" width=auto height=auto;>调频信号示例</video></p>
<h3 id="2-2-数字调制"><a href="#2-2-数字调制" class="headerlink" title="2.2 数字调制"></a><font size=3>2.2 数字调制</font></h3><blockquote>
<p>几个基本概念：</p>
<p>（1）码片：现在我们想表示一个比特1，我们可以规定4个码片代表一个比特1。</p>
<p>（2）比特：由多个码片构成。</p>
<p>（3）符号：一个符号由多个比特构成，我们一个字符要用一个字节表示就是8个比特。</p>
<p>通过下面的图应该会比较好理解。</p>
</blockquote>
<ul>
<li>通断键控</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104239625.png" alt="image-20231223104239625" style="zoom:50%;" />

<p>在我们生活中，不可能有全为0的信号的，一定会有干扰。</p>
<ul>
<li>幅移键控</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104515455.png" alt="image-20231223104515455" style="zoom:50%;" />

<ul>
<li>频移键控</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104621826.png" alt="image-20231223104621826" style="zoom:50%;" />

<p>这种方式其实才是最稳定的，我们的蓝牙BLE物理层使用的就是频移键控。但是频率变化的时候本身就会产生噪声，所以在此基础上会再加一个高斯滤波器。全称就是高斯频移键控，这样才能保证蓝牙BLE收到数据的准确性。</p>
<h2 id="3-射频频段"><a href="#3-射频频段" class="headerlink" title="3. 射频频段"></a><font size=3>3. 射频频段</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104956898.png" alt="image-20231223104956898" style="zoom:50%;" />

<p>蓝牙工作于2400~2483.5MHz 免费的ISM频段，蓝牙采用跳频扩谱技术主动的避免工作频段受干扰。</p>
<h2 id="4-射频信道"><a href="#4-射频信道" class="headerlink" title="4. 射频信道"></a><font size=3>4. 射频信道</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223110052622.png" alt="image-20231223110052622" style="zoom:50%;" />

<h2 id="5-物理层如何识别0和1？"><a href="#5-物理层如何识别0和1？" class="headerlink" title="5. 物理层如何识别0和1？"></a><font size=3>5. 物理层如何识别0和1？</font></h2><p>我们蓝牙物理信道的速率为1Mbps，最小频移范围为180KHz，那如何识别0和1？</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223110610059.png" alt="image-20231223110610059" style="zoom:50%;" />

<h1 id="三、蓝牙BLE链路层-Link"><a href="#三、蓝牙BLE链路层-Link" class="headerlink" title="三、蓝牙BLE链路层(Link)"></a><font size=3>三、蓝牙BLE链路层(Link)</font></h1><p>在链路层里面，被定义了两个设备如何通过无线电通信信息。它包含了报文、广播、数据信道的详细定义，也有规定发现其他设备的流程、广播的数据、建立的连接，链路层之所以负责这样多的工作，可能是自物理层拿到的一手消息在本层来进行功能分配以及分析是最为便捷快速的，也由此让链路层的功能变得复杂，在加上2.4G频段的干扰及噪声，让链路层可以直接表达程序员的智慧所在，想了解链路层，不得不从它的多样化功能入手。  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png" alt="image-20231223085657235" style="zoom:50%;" />

<h2 id="1-白化"><a href="#1-白化" class="headerlink" title="1. 白化"></a><font size=3>1. 白化</font></h2><p>一个问题，我们看这段数据：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223104621826.png" alt="image-20231223104621826" style="zoom:50%;" />

<p>我们把它发出去，蓝牙看控制器也是可以正常接收到的，但是接收的时候会有一个问题，就是像这样的数据00000000000000000001 ，数据之间存在大量连续的0，我们人眼来数0的话，少了还好，这么多，我们只看，会有很大的概率数错的，我们可能需要一个笔指着数。同样的，这样的数据在接收的时候，可能会导致接收器锁频失败。在蓝牙标准中有说明，每次发送的数据中不可以有连续的6个及以上的1或者0。如何解决？这个时候就出现了白化算法（whitening circle），他更像是一种随机数生成器，我们输入一段数据，通过一段白化序列，进行一个或或者与操作，得到输出数据，来降低连续的0或者1的出现频率：</p>
<table>
<thead>
<tr>
<th align="center"><strong>输入</strong></th>
<th align="center"><strong>白化序列</strong></th>
<th align="center"><strong>输出</strong></th>
</tr>
</thead>
<tbody><tr>
<td align="center">0</td>
<td align="center">0</td>
<td align="center">0</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">0</td>
<td align="center">1</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">1</td>
<td align="center">0</td>
</tr>
</tbody></table>
<p>双方蓝牙都有这样一套白化的逻辑，收到的数据可以通过这套逻辑还原原来的信号。</p>
<h2 id="2-链路层状态机"><a href="#2-链路层状态机" class="headerlink" title="2. 链路层状态机"></a><font size=3>2. 链路层状态机</font></h2><p>链路层有5个状态：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223111902089.png" alt="image-20231223111902089" style="zoom: 33%;" />

<p>每一种状态结束后，都要回归就绪态。只有在连接态才会使用蓝牙信道的数据信道，其他的几种状态都是在蓝牙的广播信道实现的。</p>
<h3 id="2-1-就绪态"><a href="#2-1-就绪态" class="headerlink" title="2.1 就绪态"></a><font size=3>2.1 就绪态</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223112056300.png" alt="image-20231223112056300" style="zoom: 33%;" />

<p>这就是就绪态，我们已经准备就绪，可以做其他任何事情了。</p>
<h3 id="2-2-扫描态"><a href="#2-2-扫描态" class="headerlink" title="2.2 扫描态"></a><font size=3>2.2 扫描态</font></h3><p>我们使用蓝牙的时候，要先配对，我们一般会拿出手机，打开蓝牙，开始扫描，这个时候就进入了扫描态。扫描态分为主动扫描和被动扫描两种。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223112616367.png" alt="image-20231223112616367" style="zoom:50%;" />

<p>比如，现在有一个卖水果的，正在大声的喊着卖水果，现在有两个人，就相当于一个蓝牙在广播着自己的信号，现在，我们有两个蓝牙，现在都在扫描其他的蓝牙，一个是在主动扫描，就像右边靠上位置的人，另一个是被动扫描，他的嘴被“封”上了，最终他们可以得到这样的信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223112844436.png" alt="image-20231223112844436" style="zoom:50%;" />

<p>处于被动扫描的只能知道卖水果的在喊卖水果，无法获得更详细的信息，也无法询问，但是主动扫描的就可以开口询问，哪里的水果？这样他不仅可以知道这里有一个蓝牙设备，还可以知道蓝牙设备更为详细的信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223113040315.png" alt="image-20231223113040315" style="zoom:50%;" />

<p>对于设备来讲，我们主动扫描的时候可以获取更多的蓝牙设备信息，比如它的设备商、它的设备类型等</p>
<h3 id="2-3-发起态"><a href="#2-3-发起态" class="headerlink" title="2.3 发起态"></a><font size=3>2.3 发起态</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223113103341.png" alt="image-20231223113103341" style="zoom:33%;" />

<p>我们前面已经扫描完了，现在要连接蓝牙，就要发起蓝牙连接的请求，就会进入发起态。就如上图，我们 扫描到蓝牙设备后，会点击扫描到的设备，然后进行配对连接。</p>
<h3 id="2-4-连接态"><a href="#2-4-连接态" class="headerlink" title="2.4 连接态"></a><font size=3>2.4 连接态</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223113454367.png" alt="image-20231223113454367" style="zoom:33%;" />

<p>连接态就是蓝牙的连接过程的状态，它分为主连接态和从连接态。</p>
<h3 id="2-5-广播态"><a href="#2-5-广播态" class="headerlink" title="2.5 广播态"></a><font size=3>2.5 广播态</font></h3><p>这个很好理解，就是我们平时打开蓝牙的时候，它可以被其他的蓝牙搜索到。我们以前用的蓝牙模块什么的，我们要进入一个配对状态，进入的这个配对状态起始就是在广播自己，告诉周围的设备自己还没有配对，其他的设备可以过来连自己。</p>
<h2 id="3-数据包格式"><a href="#3-数据包格式" class="headerlink" title="3. 数据包格式"></a><font size=3>3. 数据包格式</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114003807.png" alt="image-20231223114003807" style="zoom:50%;" />

<h3 id="3-1-前导格式"><a href="#3-1-前导格式" class="headerlink" title="3.1 前导格式"></a><font size=3>3.1 前导格式</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114026698.png" alt="image-20231223114026698" style="zoom:50%;" />

<p>使用哪种格式？格式由接入地址决定。</p>
<h3 id="3-2-接入地址"><a href="#3-2-接入地址" class="headerlink" title="3.2 接入地址"></a><font size=3>3.2 接入地址</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114131563.png" alt="image-20231223114131563" style="zoom:50%;" />

<p>蓝牙广播的时候，数据的发送地址都是这个0x8E89BED6。当两个蓝牙进行配对的时候，会生成一个随机的数据通道的地址，随机的有什么好处？这样可以防止数据被人抓取解析，恶意操作者即便抓取了，也没什么太大的意义，他即便可以获取接入地址，但是也无法分辨是哪一个设备，只有两个设备之间才知道这个地址是哪个设备的。</p>
<h3 id="3-3-报头"><a href="#3-3-报头" class="headerlink" title="3.3 报头"></a><font size=3>3.3 报头</font></h3><h4 id="3-3-1-广播报头"><a href="#3-3-1-广播报头" class="headerlink" title="3.3.1 广播报头"></a><font size=3>3.3.1 广播报头</font></h4><ul>
<li>广播报头的格式：</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223115023394.png" alt="image-20231223115023394" style="zoom:50%;" />

<ul>
<li>广播报头的类型</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114320752.png" alt="image-20231223114320752" style="zoom:50%;" />

<h4 id="3-3-2-数据报头"><a href="#3-3-2-数据报头" class="headerlink" title="3.3.2 数据报头"></a><font size=3>3.3.2 数据报头</font></h4><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223114909792.png" alt="image-20231223114909792" style="zoom:50%;" />

<h3 id="3-4-长度"><a href="#3-4-长度" class="headerlink" title="3.4 长度"></a><font size=3>3.4 长度</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223115058268.png" alt="image-20231223115058268" style="zoom:50%;" />

<h2 id="4-信道映射"><a href="#4-信道映射" class="headerlink" title="4. 信道映射"></a><font size=3>4. 信道映射</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223134706721.png" alt="image-20231223134706721" style="zoom: 50%;" />

<p>重新编号的时候，37、38和39三个通道是广播通道，他们通道号连续，但是对应的物理通道以及频率却是相隔很远，这样可以很好的避开WiFi的信道，避免WiFi的影响：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223135026045.png" alt="image-20231223135026045" style="zoom: 33%;" />

<h2 id="5-跳频"><a href="#5-跳频" class="headerlink" title="5. 跳频"></a><font size=3>5. 跳频</font></h2><p><strong>使用无线设备时不稳定的连接、数据传输不完整等问题</strong>都是常见的无线通信问题，而蓝牙跳频技术正是为了解决这些问题而开发的一种重要的无线通信技术。</p>
<p>蓝牙跳频技术主要基于频率跳跃技术，即通过在不同频率上快速跳跃来发送数据。这种技术可以防止干扰和噪声影响数据传输，提高数据传输的可靠性。具体来说，当某条频率受到干扰或噪声时，系统会自动切换到其他频率上进行传输，从而确保数据的完整性和稳定性。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223135256582.png" alt="image-20231223135256582" style="zoom:33%;" />

<p>不同的信道，可能干扰程度不同，所以一般会检测信道是否干扰严重，进行自适应跳频，避开干扰严重的信道。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223135026045.png" alt="image-20231223135026045" style="zoom: 33%;" />

<h1 id="四、控制接口层-HCI"><a href="#四、控制接口层-HCI" class="headerlink" title="四、控制接口层(HCI)"></a><font size=3>四、控制接口层(HCI)</font></h1><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png" alt="image-20231223085657235" style="zoom:50%;" />

<p>HCI是什么？如上图，HCI就是HOST和Controller之间的通道。用来桥接Host和Controller Devices。HCI是一个标准的蓝牙用的接口，用来Host发给Controller命令，HOST从controller接收events，和HOST发给Controller数据，和从HOST从Controller接收数据。HOST就是指我们的主控芯片，Microcontroller&#x2F; MCU &#x2F; μCON &#x2F; MPU等。Controller就是蓝牙芯片了，比如TI的CC2564芯片。</p>
<h2 id="1-两种接口的概念"><a href="#1-两种接口的概念" class="headerlink" title="1. 两种接口的概念"></a><font size=3>1. 两种接口的概念</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223140327324.png" alt="image-20231223140327324" style="zoom: 36%;" />

<p>HCI的物理接口有UART、USB和SDIO等几种，如上图，它其实就是一个实际存在的接口，就像我们的USB口，网口等这些，主机和蓝牙控制器不在同一块芯片上，这个时候就需要有物理接口来完成两者之间的数据传输。控制器主要就是用来接收主机传输过来的数据并发送出去，也会将从外界其他设备接收到的数据向上传输到主机，控制器中可能就是一个物理层加一个链路层，然后通过HCI与主机进行通信，完成数据的传输。</p>
<p>那什么是逻辑接口呢？我们有了物理接口，那么数据的传输怎么实现？我们可以把逻辑接口理解为驱动，就像这个usb为什么可以被识别？这就是通过逻辑接口实现。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142210363.png" alt="image-20231223142210363" style="zoom:34%;" />

<h2 id="2-数据格式"><a href="#2-数据格式" class="headerlink" title="2. 数据格式"></a><font size=3>2. 数据格式</font></h2><p>HCI基本数据格式如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142251741.png" alt="image-20231223142251741" style="zoom:50%;" />

<h3 id="2-1-命令数据包格式"><a href="#2-1-命令数据包格式" class="headerlink" title="2.1 命令数据包格式"></a><font size=3>2.1 命令数据包格式</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142330264.png" alt="image-20231223142330264" style="zoom:50%;" />

<h3 id="2-2-事件数据包格式"><a href="#2-2-事件数据包格式" class="headerlink" title="2.2 事件数据包格式"></a><font size=3>2.2 事件数据包格式</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142414270.png" alt="image-20231223142414270" style="zoom:50%;" />

<h2 id="3-功能说明"><a href="#3-功能说明" class="headerlink" title="3. 功能说明"></a><font size=3>3. 功能说明</font></h2><h3 id="3-1-复位"><a href="#3-1-复位" class="headerlink" title="3.1 复位"></a><font size=3>3.1 复位</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142810641.png" alt="image-20231223142810641" style="zoom:50%;" />

<h3 id="3-2-读取MAC地址"><a href="#3-2-读取MAC地址" class="headerlink" title="3.2 读取MAC地址"></a><font size=3>3.2 读取MAC地址</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142914342.png" alt="image-20231223142914342" style="zoom:50%;" />

<h3 id="3-3-设置事件掩码"><a href="#3-3-设置事件掩码" class="headerlink" title="3.3 设置事件掩码"></a><font size=3>3.3 设置事件掩码</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223142949736.png" alt="image-20231223142949736" style="zoom:50%;" />

<h3 id="3-4-读取缓冲区大小"><a href="#3-4-读取缓冲区大小" class="headerlink" title="3.4 读取缓冲区大小"></a><font size=3>3.4 读取缓冲区大小</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223143021957.png" alt="image-20231223143021957" style="zoom:50%;" />

<h3 id="3-5-读取控制器支持的功能"><a href="#3-5-读取控制器支持的功能" class="headerlink" title="3.5 读取控制器支持的功能"></a><font size=3>3.5 读取控制器支持的功能</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223143343840.png" alt="image-20231223143343840" style="zoom:50%;" />

<h1 id="五、逻辑链路控制和适配协议层-L2CAP"><a href="#五、逻辑链路控制和适配协议层-L2CAP" class="headerlink" title="五、逻辑链路控制和适配协议层(L2CAP)"></a><font size=3>五、逻辑链路控制和适配协议层(L2CAP)</font></h1><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223085657235.png" alt="image-20231223085657235" style="zoom:50%;" />

<p>L2CAP(逻辑链路控制和适配协议层)是一个复用层，可以让低功耗蓝牙复用三条不同的信道，为两个通信的蓝牙设备提供一个端到端的通道。它也支持数据的分割和重组功能，使得较大的报文可以在底层无线电中传输。L2CAP信道如下：</p>
<table>
<thead>
<tr>
<th align="center"><strong>信道标识符</strong></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td align="center">0x0000</td>
<td>保留：不可使用</td>
</tr>
<tr>
<td align="center">0x0001</td>
<td>经典蓝牙信令信道</td>
</tr>
<tr>
<td align="center">0x0002</td>
<td>“无连接”信道</td>
</tr>
<tr>
<td align="center">0x0004</td>
<td>属性协议</td>
</tr>
<tr>
<td align="center">0x0005</td>
<td>低功耗信令信道</td>
</tr>
<tr>
<td align="center">0x0006</td>
<td>安全管理协议</td>
</tr>
</tbody></table>
<h1 id="六、属性协议和通用属性协议"><a href="#六、属性协议和通用属性协议" class="headerlink" title="六、属性协议和通用属性协议"></a><font size=3>六、属性协议和通用属性协议</font></h1><h2 id="1-ATT属性协议"><a href="#1-ATT属性协议" class="headerlink" title="1. ATT属性协议"></a><font size=3>1. ATT属性协议</font></h2><h3 id="1-1-客户端与服务器"><a href="#1-1-客户端与服务器" class="headerlink" title="1.1 客户端与服务器"></a><font size=3>1.1 客户端与服务器</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223144305774.png" alt="image-20231223144305774" style="zoom:50%;" />

<h3 id="1-2-属性的格式"><a href="#1-2-属性的格式" class="headerlink" title="1.2 属性的格式"></a><font size=3>1.2 属性的格式</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223144614997.png" alt="image-20231223144614997" style="zoom:50%;" />

<ul>
<li>属性句柄：整个属性的内容存放的地址吧，可以这么理解，就是通过这个句柄，我们可以获取到属性的内容。</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223144907030.png" alt="image-20231223144907030" style="zoom:50%;" />

<ul>
<li>属性类型：他主要是区分数据类型。属性类型是一个UUID，他是一个唯一的标识符，2或者16字节，会有很多的特征值，我们定义了属性类型后会进行自动合成。</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223150722845.png" alt="image-20231223150722845" style="zoom:50%;" />

<ul>
<li>属性值：就是某个属性的内容或者值。</li>
<li>权限：就是一个访问权限。</li>
</ul>
<p>（1）Open：直接可以读或者写</p>
<p>（2）No Access：禁止读或者写</p>
<p>（3）Authentication：需要配对才能读或者写.</p>
<p>（4）Authorization：跟open一样，不过server返回attribute的值之前需要应用先授权。</p>
<p>（5）Signed：签名后才能读或者写，这个用得比较少。</p>
<h3 id="1-3-属性实例"><a href="#1-3-属性实例" class="headerlink" title="1.3 属性实例"></a><font size=3>1.3 属性实例</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223150423470.png" alt="image-20231223150423470" style="zoom:63%;" />

<p>这里的Type的值，其实就是对应的UUID。</p>
<h2 id="2-GATT通用属性协议"><a href="#2-GATT通用属性协议" class="headerlink" title="2. GATT通用属性协议"></a><font size=3>2. GATT通用属性协议</font></h2><p>前面我们知道GATT用来规范attribute中的数据内容，并运用group（分组）的概念对attribute进行分类管理。没有GATT，BLE协议栈也能跑，但互联互通就会出问题，也正是因为有了GATT和各种各样的应用profile，BLE摆脱了ZigBee等无线协议的兼容性困境，成了出货量最大的2.4G无线通信产品。</p>
<p>这个主要是一些定义，主要是看文档吧，在这里：<a target="_blank" rel="noopener" href="https://www.bluetooth.com/specifications/gss/">GATT Specification Supplement | Bluetooth® Technology Website</a>：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223163116264.png" alt="image-20231223163116264" />

<p>还有一个文档：<a target="_blank" rel="noopener" href="https://www.bluetooth.com/specifications/assigned-numbers/">Assigned Numbers | Bluetooth® Technology Website</a>：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165727812.png" alt="image-20231223165727812" />



<h3 id="2-1-GATT服务"><a href="#2-1-GATT服务" class="headerlink" title="2.1 GATT服务"></a><font size=3>2.1 GATT服务</font></h3><p>可以看《Assigned Numbers》——3.4 GATT Services：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223164226974.png" alt="image-20231223164226974" />

<p>在代码中的定义情况可以看这里：<a target="_blank" rel="noopener" href="https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/uuids/service_uuids.yaml">bluetooth-SIG &#x2F; public &#x2F; assigned_numbers &#x2F; uuids &#x2F; service_uuids.yaml — Bitbucket</a>，例如Generic Access：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223164827374.png" alt="image-20231223164827374" />

<h3 id="2-2-GATT特征"><a href="#2-2-GATT特征" class="headerlink" title="2.2 GATT特征"></a><font size=3>2.2 GATT特征</font></h3><p>可以看《Assigned Numbers》——3.8 Characteristics：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223164612470.png" alt="image-20231223164612470" />

<p>在代码中的定义情况可以看这里：<a target="_blank" rel="noopener" href="https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/uuids/characteristic_uuids.yaml">bluetooth-SIG &#x2F; public &#x2F; assigned_numbers &#x2F; uuids &#x2F; characteristic_uuids.yaml — Bitbucket</a>，例如Aerobic Heart Rate Lower Limit：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223164956287.png" alt="image-20231223164956287" />

<h3 id="2-3-GATT描述符"><a href="#2-3-GATT描述符" class="headerlink" title="2.3 GATT描述符"></a><font size=3>2.3 GATT描述符</font></h3><p>可以看《Assigned Numbers》——3.7 Descriptors：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165131874.png" alt="image-20231223165131874" />

<p>在代码中的定义情况可以看这里：<a target="_blank" rel="noopener" href="https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/uuids/descriptors.yaml">bluetooth-SIG &#x2F; public &#x2F; assigned_numbers &#x2F; uuids &#x2F; descriptors.yaml — Bitbucket</a>，例如Aerobic Heart Rate Lower Limit：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165219131.png" alt="image-20231223165219131" />

<h3 id="2-4-GATT声明"><a href="#2-4-GATT声明" class="headerlink" title="2.4 GATT声明"></a><font size=3>2.4 GATT声明</font></h3><p>可以看《Assigned Numbers》——3.6 Declarations：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165319778.png" alt="image-20231223165319778" />

<p>在代码中的定义情况可以看这里：<a target="_blank" rel="noopener" href="https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/uuids/declarations.yaml">bluetooth-SIG &#x2F; public &#x2F; assigned_numbers &#x2F; uuids &#x2F; declarations.yaml — Bitbucket</a>，例如Primary Service：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/LV03-01-%E8%93%9D%E7%89%99-02-%E8%93%9D%E7%89%99BLE%E5%9F%BA%E7%A1%80/img/image-20231223165453992.png" alt="image-20231223165453992" />

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/85707029.html">LV03-01-蓝牙-02-蓝牙BLE基础</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2024年01月07日 - 11:45</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/85707029.html" title="LV03-01-蓝牙-02-蓝牙BLE基础">https://sumumm.github.io/post/85707029.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV21-%E5%A4%A9%E7%8C%AB%E7%B2%BE%E7%81%B5IOT/" rel="tag"><i class="fa fa-tag"></i> LV21-天猫精灵IOT</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/a90e1df0.html" rel="prev" title="LV03-02-蓝牙Mesh基础-01-蓝牙Mesh简介">
                  <i class="fa fa-angle-left"></i> LV03-02-蓝牙Mesh基础-01-蓝牙Mesh简介
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/bb7e01c5.html" rel="next" title="LV03-01-蓝牙-01-蓝牙发展史">
                  LV03-01-蓝牙-01-蓝牙发展史 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
